import { defineConfig, loadEnv } from 'vite'
import path from "path";
import createVitePlugins from "./vite/plugins"

// https://vitejs.dev/config/
export default defineConfig(({mode, command})=>{
  const env = loadEnv(mode, process.cwd());
  env.VITE_COMMAND = command;
  env.VITE_MODE = mode;
  return {
    base: "./",
    plugins: createVitePlugins(env),
    define: {
      global: "globalThis",
      'process.env': {
        ...process.env,
        ...env
      }
    },
    resolve: {
      alias: {
        "@": path.resolve(process.cwd(), "src"),
        "#": path.resolve(process.cwd(), "src/types"),
      },
    },
    // optimizeDeps: {
    //   esbuildOptions: {
    //     define: {
    //       global: "globalThis",
    //     }
    //   },
    // },
    build:{
      manifest: true,
      sourcemap: false,
      commonjsOptions: {
        ignoreTryCatch: false,
        transformMixedEsModules: true,
      },
    }
  }
})
